
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>XXX图书管理系统新增会员</title>
</head>
<body>
<a href="index.php">返回首页</a><br>

<?php
include "functions.php";
$usertype=$_POST['usertype'];
$userid=$_POST['userid'];
$username=$_POST['username'];
$password1=$_POST['password1'];
$password2=$_POST['password2'];

if(hasUser($userid)){
    echo "该手机号已被注册";
    echo "<br>";
    $url1='/makeCard.php';
    echo "<a href='".$url1."'>".'重新进行办卡操作'."</a><br>";
    $url2='/index.php';
    echo "<a href='".$url2."'>".'返回首页'."</a>";
    die();
}elseif ($password1!=$password2){
    echo "两次输入密码不一致";
    echo "<br>";
    $url1='/makeCard.php';
    echo "<a href='".$url1."'>".'重新进行办卡操作'."</a><br>";
    $url2='/index.php';
    echo "<a href='".$url2."'>".'返回首页'."</a>";
    die();
}else{
    $db=connectDB();
    $statement=$db->prepare('insert into Users (ID,Name,UsrType,Password) VALUES (:id,:name,:usrtype,:password)');
    $usertype=($usertype=='admin'?'admin':'usr');
    $statement->execute([':id'=>$userid,':name'=>$username,':usrtype'=>$usertype,':password'=>$password1]);
    echo "开卡成功！\n";
    $url='/index.php';
    echo "<a href='".$url."'>".'返回首页'."</a>";
}


?>



</body>
</html>